package com.dqhl.community.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.model.ExpressReceive;
import com.dqhl.community.util.Dlog;
import com.dqhl.community.util.ViewHolder;
import com.dqhl.community.view.ConfirmDialog;

/**
 * Created by cheng on 2016/9/2.
 * 优惠券使用情况列表 adapter
 */
public class ExpressListAdapter extends BaseAdapter {

    private Context context;
//    private List<ExpressReceive> expressReceiveList;
    private ExpressReceive expressReceive;
    private LayoutInflater inflater;
    private ConfirmDialog confimDialog;

    public ExpressListAdapter(Context context, ExpressReceive expressReceive) {
        this.context = context;
        this.expressReceive = expressReceive;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return 1;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.lv_item_express_receive, parent, false);
        }
        final TextView consignee = ViewHolder.get(convertView, R.id.tv_user_name);
        TextView add_time = ViewHolder.get(convertView, R.id.tv_date);
        final TextView phone = ViewHolder.get(convertView, R.id.tv_tel);
        TextView status = ViewHolder.get(convertView,R.id.tv_arrive_address);

//        ExpressReceive expressReceive = expressReceiveList.get(position);
        consignee.setText(expressReceive.getConsignee());
        Dlog.e(expressReceive.getPhone()+"FF"+expressReceive.getAdd_time());
        add_time.setText(expressReceive.getAdd_time());
        phone.setText(expressReceive.getPhone());
        if("0".equals(expressReceive.getState())){
            status.setText("您的快递已到达代收地点");
        }else {
            status.setText("您的快递已领取");
        }
        phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                confimDialog = new ConfirmDialog(context,"确定打电话吗?","确定","取消");
                confimDialog.setButtonClickListener(new ConfirmDialog.ButtonClickListener() {
                    @Override
                    public void doConfirm() {
                        String action = Intent.ACTION_CALL;
                        String number = phone.getText().toString().trim();
                        Uri data = Uri.parse("tel:"+number);
                        Intent intent1 = new Intent(action,data);
                        context.startActivity(intent1);
                        confimDialog.dismiss();
                    }

                    @Override
                    public void doCancel() {
                        confimDialog.dismiss();
                    }
                });
                confimDialog.show();
            }
        });

        return convertView;
    }
}
